import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({
	state: {
		hasLogin: false,
		userInfo: null,
		cityId: '610100',
		current: 0,
		token: '',
		brandList: null,
	},
	getters: {
		isCurrent(state) {
			return state.current
		},
		token(state) {
			return state.token
		},
		userInfo(state) {
			return state.userInfo
		},
		brandList(state) {
			return state.brandList
		},
	},
	mutations: {
		login(state, provider) {
			state.hasLogin = true;
			state.userInfo = provider;
			uni.setStorage({ //缓存用户登陆状态
				key: 'userInfo',
				data: provider
			})
		},
		logout(state) {
			state.hasLogin = false;
			state.userInfo = {};
			uni.removeStorage({
				key: 'userInfo'
			})
		},
		cityId(state, provider) {
			state.cityId = provider;
			uni.setStorage({
				key: 'cityId',
				data: provider
			})
		},
		current(state, provider) {
			state.current = provider;
		},
		brandList(state, provider) {
			state.brandList = provider;
			uni.setStorage({
				key: 'brandList',
				data: provider
			})
		},
	},
	actions: {
		// this.$api.MsgPull(data).then(res => {
		// 	console.log(res)
		// });
	}
})

export default store
